home *** CD-ROM | disk | FTP | other *** search
/ Freaks Macintosh Archive / Freaks Macintosh Archive.bin / Freaks Macintosh Archives / Hacking & Misc / bundle of exploits.sit / bundle of exploits / sgi_cgihandler.txt < prev    next >
Text File  |  1998-07-17  |  4KB  |  95 lines

  1. /cgi-bin/handler is a small perl program that allows (in theory) 
  2. to read and download files under the system's root directory.
  3. In fact it allows you to execute any command remotely
  4. on the target machine.
  5.  
  6. Here's how it works:
  7. "handler" reads PATH_INFO from the environment and then concatenates it
  8. with a default "root directory" (let's say /var/www/htdocs). It then runs
  9. a "validity check" on the result. But it only checks for ".." not for
  10. other potential offensive special chars.
  11. It then uses "open (INPUT, $doc)" where $doc is the result of the
  12. concatenation.
  13. If you're familiar with PERL you know that if a '|' character follows the
  14. filename, perl will treat that filename as a command. It runs it and gives
  15. you STDOUT.
  16. The way to exploit this "feature" for cgi-bin/handler is:
  17.  
  18. telnet target.machine.com 80
  19. GET /cgi-bin/handler/useless_shit;cat   /etc/passwd|?data=Download
  20. HTTP/1.0
  21.  
  22. Note that you have to use a TAB character after cat, not a space because
  23. the shell will accept it as a separator and it won't confuse the HTTP
  24. server. You can't use the %xx format (%20) because the script doesn't do
  25. any parsing (So you will not be able to give command that contain spaces).
  26.  
  27. Of course, you can use any other command instead of "cat" but remember NOT
  28. to use spaces, just tabs.
  29.  
  30. The server will display an error saying that it couldn't open
  31. "useless_shit" but it will continue anyway and execute your command.
  32.  
  33. I tested it on two Indy machines with IRIX 6.2.
  34.  
  35. And also, I think this kind of approach makes cgi-bin's written in perl
  36. more vulnerable. That is any script that does not strip special
  37. characters (not only dots, but also | and ; ) and uses "open" commands on
  38. files read from user input can be attacked. Most of the cgi-bin's I've
  39. seen do only a rudimentary check for "double-dots" and then declare the
  40. URL "sane".
  41.  
  42.  
  43. ==========================================================================
  44.  
  45.  
  46. I have had reports that my exploit for SGI's /cgi-bin/handler does not
  47. work on IRIX 6.3 (on O2).  I analyzed the code provided with IRIX
  48. 6.3 and they tried to fix it, but they actually DID NOT.
  49.  
  50. They added a new line to the script:
  51.  
  52. $doc=~s/\|*$// (in plain English, this means "remove any number of '|'s at
  53. end-of-string"). But guess what. It works just as fine if you put another
  54. TAB character after the "pipe" (so that the "pipe" is not at
  55. end-of-string, the TAB is).
  56.  
  57. The exploit should read
  58.  
  59. telnet target.machine.com 80
  60. GET /cgi-bin/handler/whatever;cat       /etc/passwd|    ?data=Download
  61. HTTP/1.0
  62.  
  63. It tricks the script into executing the command anyway.
  64. Now, for those of you who want to patch it somehow, here's the best
  65. solution that has been posted to me (all credits for it go to Wolfram
  66. Schneider <wosch@apfel.de>)
  67.  
  68. All "open" commands should check if the their argument is really a
  69. filename. You could use:
  70.  
  71. -f $doc && open (INPUT, $doc)
  72.  
  73. (Same thing as: if (-f $doc) {open (INPUT, $doc) } , the one written
  74. above is more PERL style)
  75.  
  76. So far, IRIX versions 5.3, 6.2, and now 6.3 are vulnerable.
  77.  
  78.  
  79. ===========================================================================
  80.  
  81.  
  82. If you have untrusted local users who can install their own cgi-bin
  83. stuff (I know of at least one large site that is in this situation),
  84. this isn't enough.  /cgi-bin/handler/whatever;cat\t/etc/passwd\|\t may
  85. well exist, and open() will _still_ take it as a pipe.
  86.  
  87.  
  88. ===========================================================================
  89.  
  90.  
  91. IRIX 6.4 is also vulnerable to this exploit.
  92.  
  93.  
  94. ===========================================================================
  95.